<template>
  <el-table :data="tableData" stripe height="100%">
    <el-table-column
      v-for="column in tableColumns"
      :key="column.code"
      :prop="column.code"
      :label="column.name"
      :width="column.width ? column.width : 100"
      :formatter="
        (row, column, cellValue, index) => {
          return cell_formatter(column, cellValue, tableColumns)
        }
      "
    />
    <el-table-column width="100" label="操作">
      <template #default="scope">
        <el-button size="small" @click="print(scope.row)"> 打印条码 </el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script lang="ts" setup>
import { location_define } from '@/meta/index'
import type { bd_location } from '@/types/basedata'
import { fill_ref_info, cell_formatter } from '@/utils/common'
import { onMounted, ref } from 'vue'
import { useDbStore } from '@/stores/modules/database'
import copy from 'copy-to-clipboard'
import { ElMessageBox } from 'element-plus'
import { e_code_prefix } from '@/types/enum'
const dbStore = useDbStore()
const tableColumns = location_define
const tableData = ref<bd_location[]>()
const print = (p: bd_location) => {
  copy(e_code_prefix.库位 + p.barcode)
  ElMessageBox.alert('条码号已复制到剪切板', '提示')
}
onMounted(() => {
  const tmp = dbStore.location
  fill_ref_info(tmp, location_define)
    .then(() => {
      tableData.value = tmp
    })
    .catch(() => {
      console.log('err')
    })
})
</script>
